﻿using System;
using System.Data;
using System.Collections;
using System.Text.RegularExpressions;
using System.Text;
using System.Web.Caching;

using LTJ.Common;
using LTJ.Data;
using LTJ.Config;
using LTJ.Entity;
using LTJ.Common.Generic;
using LTJ.Cache;

namespace LTJ.FrameWork
{
    /// <summary>
    /// 操作日志操作
    /// </summary>
    public class OpLogs
    {
        /// <summary>
        /// 创建访问日志
        /// </summary>
        /// <param name="uid">用户ID</param>
        /// <param name="lname">登录名</param>
        /// <param name="gid">组ID</param>
        /// <param name="cid">访问企业ID</param>
        /// <param name="ip">访问IP</param>
        /// <param name="actid">访问动作</param>
        /// <param name="actdesc">具体内容描述</param>
        /// <returns>日志ID</returns>
        public static int CreateVisitLog(int uid, string lname, int gid, int cid, string ip, int actid, string actstr, string actdesc)
        {
            return Data.DataProvider.OpLogs.CreateVisitLog(uid, lname, gid, cid, ip, actid, actstr, actdesc);
        }

        /// <summary>
        /// 创建企业访问日志
        /// </summary>
        /// <param name="uid">用户ID</param>
        /// <param name="lname">登录名</param>
        /// <param name="gid">组ID</param>
        /// <param name="cid">访问企业ID</param>
        /// <param name="ip">访问IP</param>
        /// <param name="actid">访问动作</param>
        /// <returns>日志ID</returns>
        public static int CreateCompanyLoginLog(int uid, string lname, int gid, int cid, string ip)
        {
            return CreateVisitLog(uid, lname, gid, cid, ip, OpAction.CompanyLogin.ActionID, OpAction.CompanyLogin.ActionDescription, "");
        }
        /// <summary>
        /// 创建企业用户访问日志
        /// </summary>
        /// <param name="uid">用户ID</param>
        /// <param name="lname">登录名</param>
        /// <param name="gid">组ID</param>
        /// <param name="cid">访问企业ID</param>
        /// <param name="ip">访问IP</param>
        /// <param name="actid">访问动作</param>
        /// <returns>日志ID</returns>
        public static int CreateCompanyUserLoginLog(int uid, string lname, int gid, int cid, string ip)
        {
            return CreateVisitLog(uid, lname, gid, cid, ip, OpAction.Login.ActionID, OpAction.Login.ActionDescription, "");
        }
        /// <summary>
        /// 创建企业操作日志
        /// </summary>
        /// <param name="uid">用户ID</param>
        /// <param name="lname">登录名</param>
        /// <param name="gid">组ID</param>
        /// <param name="cid">访问企业ID</param>
        /// <param name="ip">访问IP</param>
        /// <param name="actid">访问动作</param>
        /// <returns>日志ID</returns>
        public static int CreateCompanyOPLog(UserInfo uinfo, string ip, int actid, string logstr)
        {
            return CreateVisitLog(uinfo.id, uinfo.lname, uinfo.gid, uinfo.cid, ip, actid, OpAction.GetActionDescriptionById(actid), logstr);
        }

        /// <summary>
        /// 根据条件获取全部企业管理员访问日志集合数量
        /// </summary>
        public static int GetAllCompanyVisitLogCount(string querystring)
        {
            return Data.DataProvider.OpLogs.GetAllCompanyVisitLogCount(querystring);
        }

        /// <summary>
        /// 获取全部企业管理员访问日志分页操作
        /// </summary>
        public static DataTable GetAllCompanyVisitLogsByPage(int pageindex, int pagesize, string condition, string ordercolumn, string ordertype)
        {
            return Data.DataProvider.OpLogs.GetAllCompanyVisitLogsByPage(pageindex, pagesize, condition, ordercolumn == "" ? "id" : ordercolumn, ordertype == "" ? "desc" : ordertype);
        }

        /// <summary>
        /// 删除访问日志
        /// </summary>
        public static void DelVisitLog(string ids)
        {
            Data.DataProvider.OpLogs.DelVisitLog(ids);
        }

        #region 线路日志记录
        /// <summary>
        /// 创建线路增加信息日志
        /// </summary>
        /// <param name="uid">用户ID</param>
        /// <param name="lname">登录名</param>
        /// <param name="rid">新增线路ID</param>
        /// <param name="price1">20GP</param>
        /// <param name="price2">40GP</param>
        /// <param name="price3">40HQ</param>
        /// <param name="actid">动作ID</param>
        /// <param name="logstr">动作描述</param>
        public static int LogRouteAdd(int uid, string lname, int rid, string price1, string price2, string price3)
        {
            return LogRoute(uid, lname, rid, price1, price2, price3, OpAction.RouteAdd.ActionID, OpAction.RouteAdd.ActionDescription, "");
        }

        /// <summary>
        /// 创建线路编辑信息日志
        /// </summary>
        /// <param name="uid">用户ID</param>
        /// <param name="lname">登录名</param>
        /// <param name="rid">新增线路ID</param>
        /// <param name="price1">20GP</param>
        /// <param name="price2">40GP</param>
        /// <param name="price3">40HQ</param>
        /// <param name="actid">动作ID</param>
        /// <param name="logstr">动作描述</param>
        public static int LogRouteEdit(int uid, string lname, int rid, string price1, string price2, string price3, string logstr)
        {
            return LogRoute(uid, lname, rid, price1, price2, price3, OpAction.RouteEdit.ActionID, OpAction.RouteEdit.ActionDescription, logstr);
        }

        /// <summary>
        /// 创建线路价格批量编辑信息日志
        /// </summary>
        /// <param name="uid">用户ID</param>
        /// <param name="lname">登录名</param>
        /// <param name="rid">线路ID</param>
        /// <param name="price1">20GP</param>
        /// <param name="price2">40GP</param>
        /// <param name="price3">40HQ</param>
        /// <param name="actid">动作ID</param>
        /// <param name="ids">线路ID集合</param>
        public static void LogRoutesPriceEdit(int uid, string lname, string ids)
        {
            foreach (string str in ids.Split(','))
            {
                int rid = TypeConverter.StrToInt(str, 0);
                RouteBaseInfo rbinfo = RouteBases.GetRouteBaseInfo(rid);

                if (rid > 0 && rbinfo != null)
                    LogRouteEdit(uid, lname, rid, rbinfo._20GP, rbinfo._40GP, rbinfo._40HQ, "批量价格调整");
            }
        }

        /// <summary>
        /// 创建线路基本信息批量编辑信息日志
        /// </summary>
        /// <param name="uid">用户ID</param>
        /// <param name="lname">登录名</param>
        /// <param name="rid">线路ID</param>
        /// <param name="price1">20GP</param>
        /// <param name="price2">40GP</param>
        /// <param name="price3">40HQ</param>
        /// <param name="actid">动作ID</param>
        /// <param name="ids">线路ID集合</param>
        public static void LogRoutesBaseEdit(int uid, string lname, string ids)
        {
            foreach (string str in ids.Split(','))
            {
                int rid = TypeConverter.StrToInt(str, 0);
                RouteBaseInfo rbinfo = RouteBases.GetRouteBaseInfo(rid);

                if (rid > 0 && rbinfo != null)
                    LogRouteEdit(uid, lname, rid, rbinfo._20GP, rbinfo._40GP, rbinfo._40HQ, "批量基本信息调整");
            }
        }

        /// <summary>
        /// 创建线路信息日志
        /// </summary>
        /// <param name="uid">用户ID</param>
        /// <param name="lname">登录名</param>
        /// <param name="rid">线路ID</param>
        /// <param name="price1">20GP</param>
        /// <param name="price2">40GP</param>
        /// <param name="price3">40HQ</param>
        /// <param name="actid">动作ID</param>
        /// <param name="actdesc">动作描述</param>
        public static int LogRoute(int uid, string lname, int rid, string price1, string price2, string price3, int actid, string actstr, string actdesc)
        {
            return Data.DataProvider.OpLogs.CreateRouteLog(uid, lname, rid, price1, price2, price3, actid, actstr, actdesc);
        }

        /// <summary>
        /// 根据条件获取全部企业线路操作日志集合数量
        /// </summary>
        public static int GetAllRouteLogCount(string querystring)
        {
            return Data.DataProvider.OpLogs.GetAllRouteLogCount(querystring);
        }

        /// <summary>
        /// 获取全部企业线路操作日志分页操作
        /// </summary>
        public static DataTable GetRouteLogsByPage(int pageindex, int pagesize, string condition, string ordercolumn, string ordertype)
        {
            return Data.DataProvider.OpLogs.GetRouteLogsByPage(pageindex, pagesize, condition, ordercolumn == "" ? "id" : ordercolumn, ordertype == "" ? "desc" : ordertype);
        }

        /// <summary>
        /// 删除线路操作日志
        /// </summary>
        public static void DelRouteLogs(string ids)
        {
            Data.DataProvider.OpLogs.DelRouteLogs(ids);
        }
        /// <summary>
        /// 根据条件获取线路日志集合
        /// </summary>
        public static DataTable GetRouteLogTable(string conditions)
        {
            return Data.DataProvider.OpLogs.GetRouteLogTable(conditions);
        }
        /// <summary>
        /// 根据条件获取线路日志集合
        /// </summary>
        public static List<RouteLogInfo> GetRouteLogs(string conditions)
        {
            return Data.DataProvider.OpLogs.GetRouteLogs(conditions);
        }
        #endregion

        #region 规则操作日志
        /// <summary>
        /// 创建规则增加日志
        /// </summary>
        /// <param name="uid">用户ID</param>
        /// <param name="lname">登录名</param>
        /// <param name="cid">规则所属公司</param>
        /// <param name="rid">规则ID</param>
        /// <param name="price1">20GP</param>
        /// <param name="price2">40GP</param>
        /// <param name="price3">40HQ</param>
        public static int LogRuleAdd(int uid, string lname, int cid, int rid, string price1, string price2, string price3)
        {
            return LogRule(uid, lname, cid, rid, price1, price2, price3, OpAction.RuleAdd.ActionID, OpAction.RuleAdd.ActionDescription, "");
        }
        /// <summary>
        /// 创建规则编辑日志
        /// </summary>
        /// <param name="uid">用户ID</param>
        /// <param name="lname">登录名</param>
        /// <param name="cid">规则所属公司</param>
        /// <param name="rid">规则ID</param>
        /// <param name="price1">20GP</param>
        /// <param name="price2">40GP</param>
        /// <param name="price3">40HQ</param>
        /// <param name="logstr">内容</param>
        public static int LogRuleEdit(int uid, string lname, int cid, int rid, string price1, string price2, string price3, string logstr)
        {
            return LogRule(uid, lname, cid, rid, price1, price2, price3, OpAction.RuleEdit.ActionID, OpAction.RuleEdit.ActionDescription, logstr);
        }
        /// <summary>
        /// 创建规则日志
        /// </summary>
        /// <param name="uid">用户ID</param>
        /// <param name="lname">登录名</param>
        /// <param name="cid">规则所属公司</param>
        /// <param name="rid">规则ID</param>
        /// <param name="price1">20GP</param>
        /// <param name="price2">40GP</param>
        /// <param name="price3">40HQ</param>
        /// <param name="actid">动作ID</param>
        /// <param name="actdesc">动作描述</param>
        public static int LogRule(int uid, string lname, int cid, int rid, string price1, string price2, string price3, int actid, string actstr, string actdesc)
        {
            return Data.DataProvider.OpLogs.CreateRuleLog(uid, lname, cid, rid, price1, price2, price3, actid, actstr, actdesc);
        }
        /// <summary>
        /// 根据条件获取全部企业规则操作日志集合数量
        /// </summary>
        public static int GetAllRuleLogCount(string querystring)
        {
            return Data.DataProvider.OpLogs.GetAllRuleLogCount(querystring);
        }
        /// <summary>
        /// 获取全部企业规则操作日志分页操作
        /// </summary>
        public static DataTable GetRuleLogsByPage(int pageindex, int pagesize, string condition, string ordercolumn, string ordertype)
        {
            return Data.DataProvider.OpLogs.GetRuleLogsByPage(pageindex, pagesize, condition, ordercolumn == "" ? "id" : ordercolumn, ordertype == "" ? "desc" : ordertype);
        }
        /// <summary>
        /// 删除规则操作日志
        /// </summary>
        public static void DelRuleLogs(string ids)
        {
            Data.DataProvider.OpLogs.DelRuleLogs(ids);
        }
        #endregion

        #region 用户查询日志
        /// <summary>
        /// 创建用户搜索日志
        /// </summary>
        /// <param name="uid">用户ID（-1为匿名用户）</param>
        /// <param name="lname">登录名</param>
        /// <param name="visitip">访问IP</param>
        /// <param name="stype">搜索类型（默认0为整柜）</param>
        /// <param name="dportkey">目的港关键字</param>
        /// <param name="lportkey">起运港关键字</param>
        /// <param name="routeline">航线</param>
        /// <param name="boatcorp">船公司</param>
        /// <param name="oid">对象ID（整柜为线路ID）</param>
        /// <param name="actid">动作ID</param>
        /// <param name="actions">动作名称</param>
        /// <param name="acotent">动作内容</param>
        /// <param name="searchcode">编号（整柜指线路编号）</param>
        /// <returns>日志ID</returns>
        public static int CreateUserVisitLog(int uid, string lname, string visitip, int stype, string dportkey, string lportkey, string routeline, string boatcorp, int oid, int actid, string actions, string acotent, string searchcode)
        {
            return Data.DataProvider.OpLogs.CreateUserVisitLog(uid, lname, visitip, stype, dportkey, lportkey, routeline, boatcorp, oid, actid, actions, acotent, searchcode);
        }
        /// <summary>
        /// 创建用户搜索整柜数据日志
        /// </summary>
        /// <param name="uid">用户ID（-1为匿名用户）</param>
        /// <param name="lname">登录名</param>
        /// <param name="visitip">访问IP</param>
        /// <param name="stype">搜索类型（默认0为整柜）</param>
        /// <param name="dportkey">目的港关键字</param>
        /// <param name="lportkey">起运港关键字</param>
        /// <param name="routeline">航线</param>
        /// <param name="boatcorp">船公司</param>
        /// <returns>日志ID</returns>
        public static int CreateUserVisitWholeSearchLog(int uid, string lname, string visitip, string dportkey, string lportkey, string routeline, string boatcorp)
        {
            return CreateUserVisitLog(uid, lname, visitip, 0, dportkey, lportkey, routeline, boatcorp, 0, Convert.ToInt16(SearchAct.WholeSearch), EnumType.GetSearchAction(SearchAct.WholeSearch), "", "");
        }
        /// <summary>
        /// 创建用户查看整柜详情日志
        /// </summary>
        /// <param name="uid">用户ID（-1为匿名用户）</param>
        /// <param name="lname">登录名</param>
        /// <param name="visitip">访问IP</param>
        /// <param name="stype">搜索类型（默认0为整柜）</param>
        /// <param name="dportkey">目的港关键字</param>
        /// <param name="lportkey">起运港关键字</param>
        /// <param name="routeline">航线</param>
        /// <param name="boatcorp">船公司</param>
        /// <param name="oid">对象ID（整柜为线路ID）</param>
        /// <param name="searchcode">编号（整柜指线路编号）</param>
        /// <returns>日志ID</returns>
        public static int CreateUserVisitWholeViewLog(int uid, string lname, string visitip, string dportkey, string lportkey, string routeline, string boatcorp, int oid, string searchcode)
        {
            return CreateUserVisitLog(uid, lname, visitip, 0, dportkey, lportkey, routeline, boatcorp, oid, Convert.ToInt16(SearchAct.WholeView), EnumType.GetSearchAction(SearchAct.WholeView), "", searchcode);
        }
        /// <summary>
        /// 根据条件获取用户搜索日志集合
        /// </summary>
        public static int GetAllUserVisitLogCount(string querystring)
        {
            return Data.DataProvider.OpLogs.GetAllUserVisitLogCount(querystring);
        }
        /// <summary>
        /// 获取全部用户搜索日志分页操作
        /// </summary>
        public static DataTable GetAllUserVisitLogsByPage(int pageindex, int pagesize, string condition, string ordercolumn, string ordertype)
        {
            return Data.DataProvider.OpLogs.GetAllUserVisitLogsByPage(pageindex, pagesize, condition, ordercolumn == "" ? "id" : ordercolumn, ordertype == "" ? "desc" : ordertype);
        }
        /// <summary>
        /// 删除用户搜索操作日志
        /// </summary>
        public static void DelUserVisitLogs(string ids)
        {
            Data.DataProvider.OpLogs.DelUserVisitLogs(ids);
        }
        #endregion
    }
}
